# -*- coding: utf8 -*-

def printf(fmt, *args):
    print(fmt % args)

#printf("%d,%s", 1, "abc")

# 用object模拟字典，需要让全部的属性都能暴露成item,但是这样字典的几个原生关键字就不能作为key了，必须引入__getattribute__排除dict关键字。
# 如果用custom dict模拟object,那么.方法必须先排除属性再去访问item
# 两个方案的对比：attribute优先 or item优先

# 需求：
# 1.可以通过attr方式访问的map
# 2.可以拦截attr的write
# 3.可以嵌套，而且被Prop系统支持
# *可一件转为json串，而且算法保持和PropMap一致，例：p_map->ToJsonString();
# *需要实现deepcopy

class OplogValue:
    def __init__(self) -> None:
        self.__host_dict = {}

    def __getattr__(self, attr_name):
        printf("__getattr__: attr_name=%s", str(attr_name))
        return self.__host_dict[attr_name]

    def __getitem__(self, item_name):
        printf("__getitem__: item=%s", str(item_name))
        if key in self.__host_dict:
            return self.__host_dict[key]
        else:
            return getattr(self, key, default_value)

    def get(self, key, default_value = None):
        ''''''
        #printf("get: key=%s,value=%s", key, default_value)
        if key in self.__host_dict:
            return self.__host_dict[key]
        else:
            return getattr(self, key, default_value)

    def set(self, key, value):
        ''''''
        self.__host_dict.set(key, value)


    def setdefault(self, key, default_value):
        ''''''
        printf("getdefault: key=%s,default_value=%s", key, default_value)
        value = self.get(key)
        if not value:
            value = default_value
            self.set(value)
        return value
    

class CustomDict(dict):
    def __setitem__(self, k: _KT, v: _VT) -> None:

def Test1(self):
    val = OplogValue()
    _ = val["array_index"]
    _ = val.get("get_key")
    _ = val.get("get_key_with_default", "")
    _ = val.read_attribute
    _ = val.setdefault("set_default", "")

class PropStrMapProxy():
    def __init__(self, pmap) -> None:
        pass

    def 

if __name__ == "__main__":
